/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package paquete;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.image.BufferStrategy;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.CompoundControl;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.FloatControl;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.Port;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.plaf.ColorUIResource;


/**
 *
 * @author David Noriega Obregón
 */
public class frame extends javax.swing.JFrame implements Runnable {
    //Creamos el hilo de la animacion del texto
    Thread hilo;
    private final BufferStrategy bf;
    String frase = "R E P R O D U C T O R   W A V";
    int t = 0;
    //Creamos un color
    Color c = Color.BLUE;
    //Variables para controlar que se ha elegido una cancion y un grupo
    int cancion = 0;
    int grupo = 0;
    File sf=null;
    Clip ol;
    
    //Intento interno en reproduccion de sonido
    float volumen = 0;
    float paneo = 0;

    //Intento como metodo
    Clip clip = null;		// instancia del player de sonidos
    AudioInputStream sonido;
    AudioFormat formato;
    String ruta;
    FloatControl control;

    /**
     * Creates new form frame
     */
    public frame() {
        initComponents();
        //Utilizamos la resolucion de la pantalla para centrar el programa
        Dimension pantalla = Toolkit.getDefaultToolkit().getScreenSize();
        int height = pantalla.height;
        int width = pantalla.width;
        setSize(width / 2, height / 2);
        setLocationRelativeTo(null);
        setTitle("REPRODUCTOR WAV");
        setSize(600, 450);
        //Damos un borde a la aplicacion
        jPanel1.setBorder(BorderFactory.createLineBorder(new Color(185, 185, 185), 10));
        jPanel2.setBorder(BorderFactory.createLineBorder(new Color(185, 185, 185), 10));
        jPanel3.setBorder(BorderFactory.createLineBorder(new Color(185, 185, 185), 10));
        jPanel1.setLocation(width, height);
        //Mostramos solo el primer panel
        jPanel1.setVisible(true);
        jPanel2.setVisible(false);
        jPanel3.setVisible(false);
        jComboBox1.addItemListener(null);
        createBufferStrategy(2);
        bf = this.getBufferStrategy();
        hilo = new Thread(this);//instanciamos el hilo
        hilo.start();
        jButton1.setVisible(false);
        jLabel4.setIcon(new ImageIcon("src/paquete/musica-android.png"));
        //Cambiar color JOPTIONPANE
        UIManager UI = new UIManager();
        UI.put("OptionPane.background", new ColorUIResource(51, 51, 51));
    }

    //ANIMACION
    public void paint(Graphics g) {
        Graphics2D g2 = null;
        try {
            g2 = (Graphics2D) bf.getDrawGraphics();
            paint(g2);
        } finally {
            g2.dispose();
        }
        bf.show();
    }

    public void paint(Graphics2D g2) {
        super.paint(g2);
        g2.setFont(new Font("Arial", Font.BOLD, t));
        g2.setColor(c);

    }

    public void run() {
        int tamaño = frase.length();
        while (t <= tamaño) {
            jLabel2.setText(frase.substring(0, t));
            t += 1;
            try {
                hilo.sleep(150);
                repaint();
            } catch (InterruptedException e) {
            }
        }
        jButton1.setVisible(true);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jButton8 = new javax.swing.JButton();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jToggleButton1 = new javax.swing.JToggleButton();
        jToggleButton2 = new javax.swing.JToggleButton();
        jButton4 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jSlider1 = new javax.swing.JSlider();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(52, 238, 214));
        setUndecorated(true);
        setResizable(false);
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));

        jPanel1.setBackground(new java.awt.Color(51, 51, 51));
        jPanel1.setPreferredSize(new java.awt.Dimension(600, 450));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton1.setBackground(new java.awt.Color(0, 0, 0));
        jButton1.setForeground(new java.awt.Color(185, 185, 185));
        jButton1.setText("EMPEZAR");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 380, -1, -1));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/paquete/fondo2.png"))); // NOI18N
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 120, 491, 148));

        jLabel2.setFont(new java.awt.Font("Verdana", 1, 24)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(185, 185, 185));
        jLabel2.setText("R E P R O D U C T O R   D E   M Ú S I C A");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 30, -1, 35));

        getContentPane().add(jPanel1);

        jPanel2.setBackground(new java.awt.Color(51, 51, 51));
        jPanel2.setPreferredSize(new java.awt.Dimension(600, 450));

        jButton2.setBackground(new java.awt.Color(0, 0, 0));
        jButton2.setForeground(new java.awt.Color(185, 185, 185));
        jButton2.setText("VOLVER");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setBackground(new java.awt.Color(0, 0, 0));
        jButton3.setForeground(new java.awt.Color(185, 185, 185));
        jButton3.setText("SALIR");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Verdana", 1, 14)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(185, 185, 185));
        jLabel3.setText("Disco");

        jComboBox1.setBackground(new java.awt.Color(0, 0, 0));
        jComboBox1.setForeground(new java.awt.Color(185, 185, 185));
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione...", "Iron Maiden", "Warcry", "Seleccionar archivo" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/paquete/musica-android.png"))); // NOI18N

        jButton8.setBackground(new java.awt.Color(0, 0, 0));
        jButton8.setForeground(new java.awt.Color(185, 185, 185));
        jButton8.setText("ESCUCHAR");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jComboBox3.setBackground(new java.awt.Color(0, 0, 0));
        jComboBox3.setForeground(new java.awt.Color(185, 185, 185));
        jComboBox3.setMaximumRowCount(12);
        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione...", "1-", "2-", "3-", "4-" }));
        jComboBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox3ActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Verdana", 1, 14)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(185, 185, 185));
        jLabel7.setText("Canción");

        jLabel13.setForeground(new java.awt.Color(185, 185, 185));
        jLabel13.setText("DAVID NORIEGA OBREGON");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(162, 162, 162))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton8)
                        .addGap(51, 51, 51)
                        .addComponent(jLabel13)
                        .addGap(44, 44, 44)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton3)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 310, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton8)
                            .addComponent(jButton2)
                            .addComponent(jButton3))
                        .addGap(21, 21, 21))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addContainerGap())))
        );

        getContentPane().add(jPanel2);

        jPanel3.setBackground(new java.awt.Color(51, 51, 51));
        jPanel3.setPreferredSize(new java.awt.Dimension(600, 450));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton5.setBackground(new java.awt.Color(0, 0, 0));
        jButton5.setForeground(new java.awt.Color(185, 185, 185));
        jButton5.setText("VOLVER");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 400, -1, -1));

        jButton6.setBackground(new java.awt.Color(0, 0, 0));
        jButton6.setForeground(new java.awt.Color(185, 185, 185));
        jButton6.setText("SALIR");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(101, 400, -1, -1));

        jLabel5.setBackground(new java.awt.Color(185, 185, 185));
        jLabel5.setFont(new java.awt.Font("Verdana", 1, 24)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(185, 185, 185));
        jPanel3.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 33, 239, 39));

        jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/paquete/Play1.png"))); // NOI18N
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });
        jPanel3.add(jToggleButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(122, 341, 41, -1));

        jToggleButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/paquete/Pause1.png"))); // NOI18N
        jPanel3.add(jToggleButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(169, 341, 38, 40));

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/paquete/Stop1.png"))); // NOI18N
        jPanel3.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 341, 45, -1));

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/paquete/Previous1.png"))); // NOI18N
        jPanel3.add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(71, 341, 45, -1));

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/paquete/Next1.png"))); // NOI18N
        jPanel3.add(jButton9, new org.netbeans.lib.awtextra.AbsoluteConstraints(213, 341, 45, 40));
        jPanel3.add(jProgressBar1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 300, 240, -1));

        jLabel8.setForeground(new java.awt.Color(185, 185, 185));
        jLabel8.setText("NOMBRE DE CANCIÓN");
        jPanel3.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 83, 239, 28));

        jLabel9.setForeground(new java.awt.Color(185, 185, 185));
        jLabel9.setText("0:00");
        jPanel3.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 320, -1, -1));

        jLabel10.setForeground(new java.awt.Color(185, 185, 185));
        jLabel10.setText("X:XX");
        jPanel3.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 320, -1, -1));

        jSlider1.setBackground(new java.awt.Color(51, 51, 51));
        jSlider1.setPaintTicks(true);
        jPanel3.add(jSlider1, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 320, 270, 19));

        jLabel11.setForeground(new java.awt.Color(185, 185, 185));
        jLabel11.setText("VOLUMEN");
        jPanel3.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 340, -1, -1));
        jPanel3.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 117, 262, 161));

        jTextArea1.setBackground(new java.awt.Color(51, 51, 51));
        jTextArea1.setColumns(20);
        jTextArea1.setForeground(new java.awt.Color(185, 185, 185));
        jTextArea1.setRows(5);
        jTextArea1.setAutoscrolls(false);
        jTextArea1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(51, 51, 51), new java.awt.Color(153, 153, 153), new java.awt.Color(51, 51, 51), new java.awt.Color(153, 153, 153)));
        jScrollPane1.setViewportView(jTextArea1);

        jPanel3.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 20, 270, 291));

        jLabel6.setForeground(new java.awt.Color(185, 185, 185));
        jLabel6.setText("DAVID NORIEGA OBREGON");
        jPanel3.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 400, -1, -1));

        getContentPane().add(jPanel3);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        //EMPEZAR
        jPanel1.setVisible(false);
        jPanel2.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        //VOLVER DESDE PANEL 3
        jPanel2.setVisible(true);
        jPanel1.setVisible(false);
        jPanel3.setVisible(false);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        //SALIR
        System.exit(WIDTH);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
        //BOTON PLAY
        jLabel12.setIcon(new ImageIcon("src/paquete/pentagrama.gif"));
        musica();
    }//GEN-LAST:event_jToggleButton1ActionPerformed

    private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed
        //JCOMBOBOX CANCION
        int selectedIndex = jComboBox3.getSelectedIndex();
        //CONTROLAMOS EL GRUPO
        if (grupo == 1) {
            //CONTROLAMOS LA CANCION Y EL TEXTO DEL PANEL 3
            switch (selectedIndex) {
                case 1:
                cancion = 1;
                sf = new File("Balloon.wav");
                jLabel8.setText("Cancion 1");
                break;
                case 2:
                cancion = 2;
                sf = new File("Balloon.wav");
                jLabel8.setText("Cancion 2");
                break;
                case 3:
                cancion = 3;
                sf = new File("Balloon.wav");
                jLabel8.setText("Cancion 3");
                break;
                case 4:
                cancion = 4;
                sf = new File("Balloon.wav");
                jLabel8.setText("Cancion 4");
                break;
            }
        } else if (grupo == 2) {
            switch (selectedIndex) {
                case 1:
                cancion = 5;
                sf = new File("Balloon.wav");
                jLabel8.setText("Cancion 1");
                break;
                case 2:
                cancion = 6;
                sf = new File("Balloon.wav");
                jLabel8.setText("Cancion 2");
                break;
                case 3:
                cancion = 7;
                sf = new File("Balloon.wav");
                jLabel8.setText("Cancion 3");
                break;
                case 4:
                cancion = 8;
                sf = new File("Balloon.wav");
                jLabel8.setText("Cancion 4");
                break;
            }
        } else if (grupo == 3) {
            System.out.println("9");
        }

    }//GEN-LAST:event_jComboBox3ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        //BOTON ESCUCHAR

        //Comprobamos que la seleccion de archivo nos deja acceder al panel para escuchar la cancion
        if (grupo == 3) {
            jPanel1.setVisible(false);
            jPanel2.setVisible(false);
            jPanel3.setVisible(true);
        }
        //Comprobamos que hay opcion valida y una cancion seleccionada
        else if (grupo == 0 || cancion == 0) {
            JOptionPane.showMessageDialog(this, "No ha seleccionado ningun archivo válido");
            this.setBackground(c);
        }
        //Al cumplirse todo tambien accedemos al panel para escuchar la cancion
        else {
            jPanel1.setVisible(false);
            jPanel2.setVisible(false);
            jPanel3.setVisible(true);

        }
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        //JCOMBOBOX GRUPO
        int selectedIndex = jComboBox1.getSelectedIndex();
        jTextArea1.setText(" ");
        switch (selectedIndex) {
            case 0:
            //En el caso por defecto y si no se selecciona nada, cambiamos la imagen y controlamos el grupo
            this.jLabel4.setIcon(new ImageIcon("src/paquete/musica-android.png"));
            grupo=0;
            break;
            case 1:
            //En el caso de elegir el primer grupo ponemos su imagen y controlamos el grupo y el texto del panel 3
            this.jLabel4.setIcon(new ImageIcon("src/paquete/images.png"));
            jLabel5.setText("IRON MAIDEN");
            grupo = 1;
            break;
            case 2:
            //En el caso de elegir el segundo grupo ponemos su imagen y controlamos el grupo y el texto del panel 3
            this.jLabel4.setIcon(new ImageIcon("src/paquete/Warcry-logo.png"));
            jLabel5.setText("WARCRY");
            grupo = 2;
            break;
            case 3:
            //En el caso de elegir un archivo ponemos su imagen y controlamos el grupo y el texto del panel 3
            this.jLabel4.setIcon(new ImageIcon("src/paquete/imagenNO.png"));
            jLabel5.setText("DESCONOCIDO");
            grupo = 3;
            String noDisponible = "LETRA NO DISPONIBLE";
            jTextArea1.setText(noDisponible);
            break;
        }
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        //SALIR
        System.exit(WIDTH);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        //VOLVER
        jPanel1.setVisible(true);
        jPanel2.setVisible(false);
        jPanel3.setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToggleButton jToggleButton2;
    // End of variables declaration//GEN-END:variables

    private void musica() {
        AudioFileFormat aff;
        AudioInputStream ais;
        
        try {
            System.out.println("Cancion 1");
            duracion();
            
            aff = AudioSystem.getAudioFileFormat(sf);
            ais = AudioSystem.getAudioInputStream(sf);
            AudioFormat af = aff.getFormat();
            System.out.println("Cancion 2");
            DataLine.Info info = new DataLine.Info(
                    Clip.class,
                    ais.getFormat(),
                    ((int) ais.getFrameLength()
                    * af.getFrameSize()));
            ol = (Clip) AudioSystem.getLine(info);
            ol.open(ais);
            
            //JSlider
            int volumen=jSlider1.getValue();
            // Control de Volumen ( debe cumplirse 0<=volumen<=1)
			control= (FloatControl)clip.getControl( FloatControl.Type.MASTER_GAIN);
			control.setValue(volumen);	// en dB
			// Control de Balance ( debe cumplirse -1<=balance<=1)
			control= (FloatControl)clip.getControl( FloatControl.Type.PAN);
			control.setValue( paneo);
			// Ejecucion del sonido
			clip.start();
                        
            ol.loop(1);

//Clip.LOOP_CONTINUOUSLY
        } catch (UnsupportedAudioFileException ee) {
        } catch (IOException ea) {
        } catch (LineUnavailableException LUE) {
        };
    }

    
    
    //CONTROL DE VOLUMEN
    static public void setVolumen(Mixer mixer,Port.Info tipo, int valor) throws Exception
	{
		FloatControl volCtrl;
		Port linea;
		linea = (Port)mixer.getLine(tipo);
		linea.open();
		try{
			volCtrl = (FloatControl) linea.getControl(FloatControl.Type.VOLUME);
		}
		catch (Exception e) {
			javax.sound.sampled.Control[] controles = linea.getControls();
			for(int i=0;i<controles.length;i++)
			{
				if(controles[i] instanceof CompoundControl)
				{
					CompoundControl com = (CompoundControl)(controles[i]);
					javax.sound.sampled.Control[] controles2 = com.getMemberControls();
					for(int j=0;j<controles2.length;j++)
					{
						if(controles2[j].getType() == FloatControl.Type.VOLUME)
						{
							volCtrl = (FloatControl)controles2[j];
							volCtrl.setValue((valor/100.0f)*(volCtrl.getMaximum()-volCtrl.getMinimum()));
							return;
						}
					}
				}
			}
			throw e;
		}
		volCtrl.setValue((valor/100.0f)*(volCtrl.getMaximum()-volCtrl.getMinimum()));
	}
    
    
    //PRUEBA DURACION
    private void duracion() throws UnsupportedAudioFileException, IOException {
        AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(sf);
        Map properties = baseFileFormat.properties();
        String key_duration = "duration";
        Long duracion = (Long) properties.get(sf);

        System.out.println("Duracion: " + String.valueOf(duracion));
    }
}
